<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Loop querying (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Loop querying (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Loop querying (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Loop-Analysis-and-Representation.html" rel="up" title="Loop Analysis and Representation">
<link href="Loop-manipulation.html" rel="next" title="Loop manipulation">
<link href="Loop-representation.html" rel="prev" title="Loop representation">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="Loop-querying"></span><div class="header">
<p>
Next: <a href="Loop-manipulation.html" accesskey="n" rel="next">Loop manipulation</a>, Previous: <a href="Loop-representation.html" accesskey="p" rel="prev">Loop representation</a>, Up: <a href="Loop-Analysis-and-Representation.html" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Loop-querying-1"></span><h3 class="section">16.2 Loop querying</h3>
<span id="index-Loop-querying"></span>

<p>The functions to query the information about loops are declared in
<samp>cfgloop.h</samp>.  Some of the information can be taken directly from
the structures.  <code>loop_father</code> field of each basic block contains
the innermost loop to that the block belongs.  The most useful fields of
loop structure (that are kept up-to-date at all times) are:
</p>
<ul>
<li> <code>header</code>, <code>latch</code>: Header and latch basic blocks of the
loop.
</li><li> <code>num_nodes</code>: Number of basic blocks in the loop (including
the basic blocks of the sub-loops).
</li><li> <code>outer</code>, <code>inner</code>, <code>next</code>: The super-loop, the first
sub-loop, and the sibling of the loop in the loops tree.
</li></ul>

<p>There are other fields in the loop structures, many of them used only by
some of the passes, or not updated during CFG changes; in general, they
should not be accessed directly.
</p>
<p>The most important functions to query loop structures are:
</p>
<ul>
<li> <code>loop_depth</code>: The depth of the loop in the loops tree, i.e., the
number of super-loops of the loop.
</li><li> <code>flow_loops_dump</code>: Dumps the information about loops to a
file.
</li><li> <code>verify_loop_structure</code>: Checks consistency of the loop
structures.
</li><li> <code>loop_latch_edge</code>: Returns the latch edge of a loop.
</li><li> <code>loop_preheader_edge</code>: If loops have preheaders, returns
the preheader edge of a loop.
</li><li> <code>flow_loop_nested_p</code>: Tests whether loop is a sub-loop of
another loop.
</li><li> <code>flow_bb_inside_loop_p</code>: Tests whether a basic block belongs
to a loop (including its sub-loops).
</li><li> <code>find_common_loop</code>: Finds the common super-loop of two loops.
</li><li> <code>superloop_at_depth</code>: Returns the super-loop of a loop with
the given depth.
</li><li> <code>tree_num_loop_insns</code>, <code>num_loop_insns</code>: Estimates the
number of insns in the loop, on GIMPLE and on RTL.
</li><li> <code>loop_exit_edge_p</code>: Tests whether edge is an exit from a
loop.
</li><li> <code>mark_loop_exit_edges</code>: Marks all exit edges of all loops
with <code>EDGE_LOOP_EXIT</code> flag.
</li><li> <code>get_loop_body</code>, <code>get_loop_body_in_dom_order</code>,
<code>get_loop_body_in_bfs_order</code>: Enumerates the basic blocks in the
loop in depth-first search order in reversed CFG, ordered by dominance
relation, and breath-first search order, respectively.
</li><li> <code>single_exit</code>: Returns the single exit edge of the loop, or
<code>NULL</code> if the loop has more than one exit.  You can only use this
function if <code>LOOPS_HAVE_RECORDED_EXITS</code> is used.
</li><li> <code>get_loop_exit_edges</code>: Enumerates the exit edges of a loop.
</li><li> <code>just_once_each_iteration_p</code>: Returns true if the basic block
is executed exactly once during each iteration of a loop (that is, it
does not belong to a sub-loop, and it dominates the latch of the loop).
</li></ul>

<hr>
<div class="header">
<p>
Next: <a href="Loop-manipulation.html" accesskey="n" rel="next">Loop manipulation</a>, Previous: <a href="Loop-representation.html" accesskey="p" rel="prev">Loop representation</a>, Up: <a href="Loop-Analysis-and-Representation.html" accesskey="u" rel="up">Loop Analysis and Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
